package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.annotation.RepeatSubmit;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.enums.BusinessType;
import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.project.biz.admin.domain.vo.BizUserGiveAwayRecordFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizUserGiveAwayRecordQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizUserGiveAwayRecordVO;
import cn.sfrog.project.biz.admin.service.IBizUserGiveAwayRecordService;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "转赠记录接口")
@RestController
@RequestMapping("/biz/giveAwayRecord")
public class BizUserGiveAwayRecordController extends BaseController {
    @Resource
    private IBizUserGiveAwayRecordService bizUserGiveAwayRecordService;

    /**
     * 查询转赠记录列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:giveAwayRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizUserGiveAwayRecordQueryVO queryVO) {
        startPage();
        List<BizUserGiveAwayRecordVO> list = bizUserGiveAwayRecordService.selectBizUserGiveAwayRecordList(queryVO);
        return getDataTable(list);
    }

    /**
     * 导出转赠记录列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('biz:giveAwayRecord:export')")
    @Log(title = "转赠记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizUserGiveAwayRecordQueryVO query) {
        List<BizUserGiveAwayRecordVO> list = bizUserGiveAwayRecordService.selectBizUserGiveAwayRecordList(query);
        ExcelUtil<BizUserGiveAwayRecordVO> util = new ExcelUtil<BizUserGiveAwayRecordVO>(BizUserGiveAwayRecordVO.class);
        util.exportExcel(response, list, "转赠记录数据");
    }

    /**
     * 获取转赠记录详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:giveAwayRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizUserGiveAwayRecordService.selectBizUserGiveAwayRecordById(id));
    }

    /**
     * 新增转赠记录
     */
    @ApiOperation("新增")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:giveAwayRecord:add')")
    @Log(title = "转赠记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizUserGiveAwayRecordFormVO form) {
        return toAjax(bizUserGiveAwayRecordService.insertBizUserGiveAwayRecord(form));
    }

    /**
     * 修改转赠记录
     */
    @ApiOperation("修改")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:giveAwayRecord:edit')")
    @Log(title = "转赠记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizUserGiveAwayRecordFormVO form) {
        return toAjax(bizUserGiveAwayRecordService.updateBizUserGiveAwayRecord(form));
    }

    /**
     * 删除转赠记录
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('biz:giveAwayRecord:remove')")
    @Log(title = "转赠记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizUserGiveAwayRecordService.deleteBizUserGiveAwayRecordByIds(ids));
    }

    /**
     * 更改状态转赠记录
     */
    @ApiOperation("更改状态")
    @PreAuthorize("@ss.hasPermi('biz:giveAwayRecord:changeStatus')")
    @Log(title = "转赠记录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody @Valid BizStatusChangeVO vo) {
        return AjaxResult.success(bizUserGiveAwayRecordService.changeStatus(vo));
    }

    /**
     * 查询用户转赠记录列表
     * @param queryVO
     * @return
     */
    @ApiOperation("查询用户转赠记录列表")
    @GetMapping("/getUserGiveAwayList")
    public TableDataInfo getUserGiveAwayList(BizUserGiveAwayRecordQueryVO queryVO) {
        startPage();
        List<BizUserGiveAwayRecordVO> list = bizUserGiveAwayRecordService.selectBizUserGiveAwayRecordList(queryVO);
        return getDataTable(list);
    }
}
